(function () {
    'use strict';
    kintone.events.on(['app.record.index.show'], function (res) {
        var kintoneRecord = new kintoneJSSDK.Record();
        var app = 291;
        var id = 8;
        setInterval(function updateData() {
            kintoneRecord.getRecord({ app, id }).then((rsp) => {
                var data = rsp.record;
                var channel1Data = Number(data.channel1.value) + Number(random(1, 10));
                var channel2Data = Number(data.channel1.value) + Number(random(1, 20));
                var channel3Data = Number(data.channel1.value) + Number(random(1, 10));
                var channel4Data = Number(data.channel1.value) + Number(random(1, 10));
                var channel5Data = Number(data.channel1.value) + Number(random(1, 10));
                var record = {
                    "channel1": { "value": channel1Data },
                    "channel2": { "value": channel2Data },
                    "channel3": { "value": channel3Data },
                    "channel4": { "value": channel4Data },
                    "channel5": { "value": channel5Data }
                }
                var revision = -1;
                kintoneRecord.updateRecordByID({ app, id, record, revision }).then((rsp) => {
                    console.log(rsp);
                }).catch((err) => {
                    // This SDK return err with KintoneAPIException
                    console.log(err);
                });
            }).catch((err) => {
                // This SDK return err with KintoneAPIException
                console.log(err);
            });
            return updateData;
        }(), 3000)
    });

    function random(lower, upper) {
        return Math.floor(Math.random() * (upper - lower)) + lower;
    }
}());